package org.graduation.rbac.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.graduation.model.common.RBAC.*;

public class QueryWrapperFactory {
    public static LambdaQueryWrapper<UserPermission> existAdmin(Long pId, Integer uid) {
        LambdaQueryWrapper<UserPermission> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserPermission::getProject_id, pId)
                .eq(UserPermission::getUid, uid)
                .eq(UserPermission::getRoleId, Roles.ADMIN.getRoleId());
        return lambdaQueryWrapper;
    }

    public static LambdaQueryWrapper<UserPermission> getRole(Long pid, Integer uid) {
        LambdaQueryWrapper<UserPermission> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserPermission::getProject_id, pid)
                .eq(UserPermission::getUid, uid);
        return lambdaQueryWrapper;
    }

    public static LambdaQueryWrapper<RolePermission> getRolePermissions(int roleId) {
        LambdaQueryWrapper<RolePermission> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(RolePermission::getRoleId, roleId);
        return lambdaQueryWrapper;
    }

    public static LambdaQueryWrapper<UserAndNotePermissions> getUserAndNoteRole(RBACModelTag model, Integer uid) {
        LambdaQueryWrapper<UserAndNotePermissions> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserAndNotePermissions::getUid, uid)
                .eq(UserAndNotePermissions::getNoteId, model.getLongId());
        return lambdaQueryWrapper;
    }

}
